package com.qs.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.qs.dao.ConnectionManager;
import com.qs.entity.Game;
import com.qs.entity.MoonInfo;
import com.qs.inter.GameInt;

public class GameImp implements GameInt {
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	Boolean flag = true;
	int i = -1;
	
	
	public List<Game> showgame() throws Exception {
		List<Game> games = new ArrayList<Game>();
		conn = ConnectionManager.getConnction();
		String sql = "select * from Game";
		ps = conn.prepareStatement(sql);
		rs = ps.executeQuery();
		while(rs.next()){
			Game game = new Game();
			game.setGameId(rs.getInt("gameId"));
			game.setGameName(rs.getString("gameName"));
			game.setGamePictureName(rs.getString("gamePictureName"));
			game.setState(rs.getInt("state"));
			games.add(game);
		}
		return games;
	}
	
	
	public int agame(Game game) throws Exception{
		conn = ConnectionManager.getConnction();
		String sql = "update Game set state =1 where gameName = ?";
		ps = conn.prepareStatement(sql);
		ps.setString(1, game.getGameName());
		i = ps.executeUpdate();
		return i;
	}

}
